package com.itheima.manager;

import com.itheima.domain.SmsHomeNewProduct;
import com.itheima.service.db.SmsHomeNewProductService;
import com.itheima.util.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SmsHomeNewProductManager {

    @DubboReference
    SmsHomeNewProductService smsHomeNewProductService;

    public R findByNewProductPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {
        return R.success(smsHomeNewProductService.findByPage(pageNum,pageSize,productName,recommendStatus));
    }

    public R update(List<Long> ids, Integer recommendStatus) {
        for (Long id : ids) {
            smsHomeNewProductService.update(id,recommendStatus);
        }
        return R.success(null);
    }

    public R delete(List<Long> ids) {
        for (Long id : ids) {
            smsHomeNewProductService.delete(id);
        }
        return R.success(null);
    }

    public R updateSort(Long id, Integer sort) {
        smsHomeNewProductService.updateSort(id,sort);
        return R.success(null);
    }

    public R addProduct(List<SmsHomeNewProduct> homeNewProductList) {
        for (SmsHomeNewProduct smsHomeNewProduct : homeNewProductList) {
            smsHomeNewProductService.addProduct(smsHomeNewProduct);
        }
        return R.success(null);
    }
}
